package com.ssm.gbq.controller;

import com.ssm.gbq.model.Doctor;
import com.ssm.gbq.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * 医生Controller
 * @Author ssm
 * @Date 2020/5/18 17:06
 */
@Controller
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    /**
     * 获取医生列表
     * @Title: list
     * @param @return
     */
    @ResponseBody
    @RequestMapping(value = "/listDoctor",method = RequestMethod.POST)
    public HashMap<String, List<Doctor>> selectDoctorList(Doctor doctor){
        HashMap<String, List<Doctor>> result = new HashMap<>();
        List<Doctor> list = doctorService.selectDoctorList(doctor);
        result.put("data",list);
        System.out.println(list);
        return result;
    }

    /**
     * 添加医生信息
     * @Title: addDoctor
     * @param @return
     */
    @ResponseBody
    @RequestMapping(value = "/addDoctor", method = RequestMethod.POST)
    public HashMap<String, Object> addDoctor(Doctor doctor){
        HashMap<String,Object> result = new HashMap<>();
        doctorService.insertDoctor(doctor);
        return result;
    }

    /**
     * 修改学生信息
     * @Title: updateDoctor
     * @param @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateDoctor", method = RequestMethod.POST)
    public HashMap<String, Object> updateDoctor(Doctor doctor){
        HashMap<String,Object> result = new HashMap<>();
        doctorService.updateDoctor(doctor);
        return result;
    }

    /**
     * 通过id删除医生
     * @Title: delDoctorById
     * @param @return
     */
    @ResponseBody
    @RequestMapping(value = "/delDoctorById", method = RequestMethod.POST)
    public HashMap<String, Object> delDoctorById(Integer id){
        HashMap<String,Object> result = new HashMap<>();
        doctorService.delDoctorById(id);
        return result;
    }

    /**
     * 搜索医生信息
     * @param doctors
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/serchDoctor", method = RequestMethod.POST)
    public HashMap<String, Object> serchDoctor(Doctor doctors){
        HashMap<String,Object> result = new HashMap<>();
        List<Doctor> list = doctorService.serchDoctor(doctors);
        result.put("doctor", list);
        return result;
    }

}
